<!-- photos -->
<div id="tabs">
    <!-- tab headers -->
	<ul>
		<li><a href="#tabs-0">основной</a></li>	
		<li><a href="#">+</a></li>
	</ul>
    <div id="tabs-0" style="padding-top: 20px">
   	    <span style="margin-left: 10px" class="btn btn-success fileinput-button" >
    		<span>Добавить</span>
            <input class="fileupload" type="file" name="files0" data-url="slide/uploadImage/0">
    	</span>
        <div id="gallery_container0"></div>
        <div class="clear"></div>
    </div>
</div>

<!-- Dialogs -->
<div id="editImage" style="display: none">
    <div id="updatingImg" style='float:left;'>
        <img src="" />
    </div>
</div>
<!-- END Dialogs -->

<!-- Dialogs -->
<div id="errorMasseageDialog" style="display: none"></div>	
<!-- END Dialogs -->

<script src="{site_url('js/jquery-ui.min.js')}" type="text/javascript"></script>
<script src="{site_url('js/uploader/vendor/jquery.ui.widget.js')}"></script>
<script src="{site_url('js/uploader/jquery.iframe-transport.js')}"></script>
<script src="{site_url('js/uploader/jquery.fileupload.js')}"></script>
<script src="{site_url('js/imgbox/jquery.imgbox.pack.js')}" type="text/javascript"></script>
<script src="{site_url('js/jquery.contenthover.js')}"></script>

<script>

    var site_url = "{site_url()}";

    {if isset($error) && $error != ''}
        $('#errorMasseageDialog').html("{$error}");
        $('#errorMasseageDialog').dialog('open');
    {/if}
 
    {literal}

    function deleteImg(imgID)
    {
        var url = site_url+"admin/slide/deleteImage/"+imgID;
        $.post(url,{},function(data) {
            if (data != "") {
	           $("#errorMasseageDialog").empty().html(data);
			   $("#errorMasseageDialog").dialog('open');
            }
            getGalleryImages(0);
        });
    }
    
    function editImg(imgID,thumb) 
    {
        $("#updatingImg").html("<img src="+site_url+"/uploads/images/data/slide/"+thumb+" />");
        $("#editImage").dialog('open');
    }

	function getGalleryImages(collID)
	{
		var url = site_url+"admin/slide/getImages/"+collID;
		$.post(url,{ },function(data){
            var jsdata=$.parseJSON(data);
            $("#gallery_container"+collID).empty().html(jsdata.html);                         
		});
	}

	jQuery(document).ready(function()
	{
		$("#tabs").tabs({
			ajaxOptions: {
				error: function( xhr, status, index, anchor ) {
					$( anchor.hash ).html(
						"Couldn't load this tab. We'll try to fix this as soon as possible. " +
						"If this wouldn't be a demo." );
				}
			},
            show: function(event, ui) {
                getGalleryImages(0);
            }
		});

		$(".addImage").button();
        $("#errorMasseageDialog").dialog({
			autoOpen: false,
			modal: true,
			resizable: false,
			title: "Ошибка",
			buttons: {
					"OK": function(){
                       window.location.replace(site_url+"admin/slide");
				       $(this).dialog('close');
					}
				}
		});
   
       	$("#editImage").dialog({
			autoOpen: false,
			modal: true,
			width: 985,
			resizable: false,
			title: "Добавить Коллекцию",
			buttons: {
				'Закрыть': function(){
					$(this).dialog('close');
				}
			}
		});

        $('.fileupload').fileupload({
            dataType: 'json',
            done: function (e, data) {            
                getGalleryImages(0);
            },
            error: function (data) {
                $("#errorMasseageDialog").empty().html(data.responseText);
				$("#errorMasseageDialog").dialog('open');
            }
        });
	});

</script>

{/literal}